/*!
Smooth Ads Scroll: 2012/05/08 - Ha Cuong (hacuong.3t@gmail.com)
Use some ideas from Sticky Scroll v1.1
*/
(function ($){
    $.fn.containedSmoothAdsScroll = function (parrentOffsetTop, parrentHeight) {
        var $getObject = $(this).selector;
        this.css('position', 'relative');
        var objOffsetLeft = jQuery($getObject).offset().left;
        var objOffsetTop = jQuery($getObject).offset().top;
        jQuery(window).scroll(function () {            
            var scrollTop = jQuery(window).scrollTop();
            var objHeight = jQuery($getObject).height();

            if (scrollTop > objOffsetTop) {
                if ((parrentHeight + parrentOffsetTop) > (scrollTop + objHeight)) {
                    jQuery($getObject).attr('style', 'position: fixed; top: 0px; left: ' + objOffsetLeft + 'px');
                }
                else {
                    var objTop = parrentOffsetTop + parrentHeight - (objHeight + objOffsetTop);
                    jQuery($getObject).attr('style', 'top: ' + objTop + 'px; position: relative');
                }
            }
            else if (scrollTop < objOffsetTop) {
                jQuery($getObject).attr('style', 'top: 0px; position: relative');
            }
        });

    };
})(jQuery);